/**
 * 添加提示
 * window.showTip(msg, type, callback)
 * window.showSuccessTip(msg, callback)
 * window.showErrorTip(msg, callback)
 * window.showHrefTip(msg, href, disabled)
 */
(function(window, $, undefined){
	"use strict";
	
	if(!$) throw new error('The JS requires jQuery!!!');
	if(window.showTip) return;
	
	var C_TIPS_INFO = {
		'success':{'class':'success', 'msg':'操作成功'},
		'error':{'class':'error', 'msg':'操作失败'}
	}
	var C_HTML = '<div class="web-tips {class}"><div class="tips-bg"><i class="tips-icon"></i><span class="message">{msg}</span></div></div>';
	var tipsQueue = [], tipsFlag = !1;
	
	window.showTip = function(msg, type, callback){
		if('' == $.trim(msg)) return;
		var html = C_HTML;
		var tipsInfo = C_TIPS_INFO[type];
		if(!tipsInfo) return;
		tipsInfo = $.extend({}, tipsInfo, {msg:msg});
		html = html.replace(/{([^}\s]*)}/g, function(match, name){
			return tipsInfo[name];
		});
		
		var $tips = $(html).appendTo('body');
		$tips.data('callback', callback);
		tipsQueue.push($tips);
		playTips();
	}
	window.showSuccessTip = function(msg, callback){
		showTip(msg, 'success', callback);
	}
	window.showErrorTip = function(msg, callback){
		showTip(msg, 'error', callback);
	}
	window.showHrefTip = function(msg, href, disabled){
		disabled = disabled || 'button';
		$(disabled).attr('disabled', 'disabled');
		showSuccessTip(msg, function(){
			if(''!=$.trim(href)) window.location.href = href;
			else window.location.reload(true);
		});
	}
	
	function playTips(){
		if(tipsQueue.length <= 0 || tipsFlag) return;
		var $tips = tipsQueue.shift();
		var callback = $tips.data('callback');
		$tips.show()
			.delay(2000)
			.fadeOut(function(){
				$tips.remove();
				callback&&callback(this);
				tipsFlag = !1;
				playTips();
			});
		tipsFlag = !0;
	}
})(window, jQuery);




